<template>
  <view class="swiper-container">
    <uni-swiper-dot class="uni-swiper-dot-box" :info="banners" :current="current" field="content">
      <swiper class="swiper-box" :current="current" @change="changeSwiper">
        <swiper-item v-for="(item, index) in banners" :key="index">
          <view class="swiper-item" @click="clickBannerItem(item)">
            <image class="swiper-image" :src="item.image" mode="aspectFill" :draggable="false" />
            <view class="title">{{ item.title }}</view>
          </view>
        </swiper-item>
      </swiper>
    </uni-swiper-dot>
  </view>
</template>

<script>
export default {
  props: {
    banners: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      current: 0
    };
  },
  methods: {
    clickBannerItem(item) {
		
      if (item.linkurl!="") {
		   
			 console.log("第1种"); 
			console.log(item.linkurl);
        this.$tab.navigateTo(item.linkurl);
        
      } else {
		  console.log("第三种");
		  console.log(item);
		  const url='/pages/focus/focus?id='+item.id;
        this.$tab.navigateTo(url);
      }
    },
    changeSwiper(e) {
      this.current = e.detail.current;
    }
  }
};
</script>

<style scoped lang="scss">
.swiper-container {
  width: 100%;
  margin-top: 20px; /* 设置距离顶部的间距 */
}

.swiper-box {
  height: 320rpx; /* 修改图片高度 */
}

.swiper-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  height: 320rpx; /* 修改图片高度 */
  position: relative;
}

.swiper-image {
  width: 100%;
  height: 100%;
  border-radius: 15px; /* 圆角图片 */
}

.title {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%; /* 宽度占满图片 */
  height: 48px; /* 标题高度调整为 48px */
  color: white;
  font-size: 16px;
  background-color: rgba(0, 0, 0, 0.25); /* 半透明背景，透明度提高 */
  display: flex;
  align-items: center;
  justify-content: center; /* 标题居中 */
  box-sizing: border-box;
  border-bottom-left-radius: 15px; /* 下边圆角 */
  border-bottom-right-radius: 15px; /* 下边圆角 */
}

@media screen and (min-width: 500px) {
  .uni-swiper-dot-box {
    width: 400px;
    margin: 0 auto;
    margin-top: 8px;
  }

  .swiper-image {
    width: 100%;
  }
}
</style>
